package org.evs.odesk.programmingSkills;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author Dmitry Kalachov
 * 
 *         Write a program that accepts 10 student records (roll number and score) and prints them in decreasing order
 *         of scores. In case there are multiple records pertaining to the same student, the program should choose a
 *         single record containing the highest score. The program should be capable of accepting a multi-line input.
 *         Each subsequent line of input will contain a student record, that is, a roll number and a score (separated by
 *         a hyphen). The output should consist of the combination of roll number and corresponding score in decreasing
 *         order of score.
 * 
 *         INPUT to program
 * 
 *         1001-40
 *         1002-50
 *         1003-60
 *         1002-80
 *         1005-35
 *         1005-55
 *         1007-68
 *         1009-99
 *         1009-10
 *         1004-89
 * 
 *         OUTPUT from program
 * 
 *         1009-99
 *         1004-89
 *         1002-80
 *         1007-68
 *         1003-60
 *         1005-55
 *         1001-40
 * 
 */
public class Task_StudentRecords {



    public static void main(String[] args) throws IOException {

        Map<Integer, Integer> uniqStudentsAndScores = new HashMap<Integer, Integer>();

        BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));
        String[] records = new String[10];
        for (int i = 0; i < 10; i++) {
            records[i] = consoleReader.readLine().trim();
        }

        for (int i = 0; i < 10; i++) {
            String[] studentAndRecord = records[i].trim().split("-");
            int student = Integer.parseInt(studentAndRecord[0].trim());
            int score = Integer.parseInt(studentAndRecord[1].trim());

            if (uniqStudentsAndScores.containsKey(student)) {
                int currentScore = uniqStudentsAndScores.get(student);
                if (currentScore < score) {
                    uniqStudentsAndScores.put(student, score);
                }
            } else {
                uniqStudentsAndScores.put(student, score);
            }
        }

        uniqStudentsAndScores = decreaseSortByComparator(uniqStudentsAndScores);
        List list = new LinkedList(uniqStudentsAndScores.entrySet());

        for (Iterator it = list.iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            System.out.println(entry.getKey() + "-" + entry.getValue());
        }

    }

    private static Map decreaseSortByComparator(Map unsortMap) {

        List list = new LinkedList(unsortMap.entrySet());

        // sort list based on comparator
        Collections.sort(list, new Comparator() {
            public int compare(Object o1, Object o2) {
                return (-1) * ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
            }
        });

        // put sorted list into map again
        Map sortedMap = new LinkedHashMap();
        for (Iterator it = list.iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            sortedMap.put(entry.getKey(), entry.getValue());
        }
        return sortedMap;
    }

}
